<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>{{codeBookDetail.name}}-添加同名图书</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form :model="editForm" label-width="60px" :rules="editFormRules" ref="editForm" :inline="true" class="demo-form-inline">
          <el-form-item label="条形码:" prop="code">
            <el-input v-model="editForm.code" auto-complete="off" placeholder="条形码"></el-input>
          </el-form-item>
          <el-form-item label="数量:" prop="number">
            <el-input v-model="editForm.number" auto-complete="off" placeholder="填写数量"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="editSubmit" size="small" type="primary">确定并保存</el-button>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  props: ['visible','codeBookDetail'], // commoent 学生点评 collection 学生采集
  components: {
  },
  data() {
    return {
      dialogVisible: false,
      editForm: {
        code: '',
        number: ''
      }, // 编辑界面数据
      editFormRules: {
        barcode: [
          {required: true, message: '请填写条形码', trigger: 'blur'}
        ],
        number: [
          {required: true, message: '请填写条形码生成数量', trigger: 'blur'}
        ]
      } // 表单验证不能为空规则
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
    }
  },
  created() {
  },
  methods: {
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option){
      return JSON.parse(JSON.stringify(option))
    },
    // 提交数据
    editSubmit () {
      // 验证信息
      let _self = this
      this.$refs['editForm'].validate((valid) => {
        if (valid) {
          _self.submitBook()
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    async submitBook () {
      this.editForm.id = this.codeBookDetail.id
      let data = await this.$post(this.api.admin_book_code_add, this.editForm);
      if (!data.code) {
        this.$message.success(data.msg)
        this.$refs['editForm'].resetFields()
        this.$emit('InitFn')
      } else {
        console.log('请求失败')
      }
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 50%;
  height:30%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 50px 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

</style>


